<?php

namespace App\Admin\Actions\Grid\RowActions;

use App\Admin\Repositories\Project;
use Dcat\Admin\Admin;
use Dcat\Admin\Widgets\Modal;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Widgets\Table;

class ActiveInfoAction extends RowAction
{
    protected $title = '   <i class="feather icon-external-link text-custom"></i> <span class="text-custom" title="">活动信息</span> &emsp;';

    public function render()
    {
        return Modal::make()
            ->lg()
            ->title($this->title)
            ->body($this->table(['row' => $this->getRow()]))
            ->button($this->title);
    }

    protected function table($input)
    {
        $row = $input['row'] ?? null;
        // dump($row);
        $data = [];
        if ($row) {
            $column = [
                'our_company', 'bank_card', 'bank_name', 'bank_addr', 'annotation', 'id_number', 'phone',
                'unit', 'active_date',
                'active_week', 'active_time', 'active_name', 'sponsor', 'role', 'expense_type_title', 'fee_type_value'
            ]; //, 'company'
            foreach ($column as $key) {
                $value = $row[$key] ?? '';
                switch ($key) {
                    case 'active_time':
                        $value = $row['active_time_begin'] . '-' . $row['active_time_end'];
                        break;
                    case 'annotation':
                        $value = $row['active_date'] . '&nbsp;&nbsp;' . $row['active_name'];
                        break;
                        // case 'id_card':
                        //     $value = $row['active_date'] . '&nbsp;&nbsp;' . $row['active_name'];
                        //     break;
                    case 'role':
                        $role = Project::getFeeTypeOptions();
                        $value = isset($role[$value]) ? $role[$value] : '';
                        break;
                    default:
                        break;
                }
                $data[] = [
                    'name' => admin_trans_field($key) . ': ',
                    'value' => $value,
                ];
            }
        }

        Admin::style('.table td{height:25px} ');
        // dd($data);
        return Table::make([], $data)->withBorder();
    }
}
